//
//  ApplyforShopViewController.m
//  Findif
//
//  Created by Mac on 2018/11/2.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "ApplyforShopViewController.h"
#import "ShopLocalViewController.h"
#import <CommonCrypto/CommonDigest.h>
#import "PGDatePickManager.h"

@interface ApplyforShopViewController ()<UITextViewDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIPickerViewDelegate,UIPickerViewDataSource,UITextFieldDelegate,PGDatePickerDelegate>{
    
    UIImagePickerController *_imagePickerController;
    NSInteger _typeIndex;
}

@property (nonatomic, assign)NSInteger count;
@property (nonatomic, strong)UIAlertController * alertVC;
@property (nonatomic, weak)UIScrollView * scrollView;
@property (nonatomic, weak)UIView * container;

@property (nonatomic, strong)UIView * topView;
@property (nonatomic, strong)UIView * bottomView;

@property (nonatomic, strong)UILabel * shopNameLabel;
@property (nonatomic, strong)UILabel * shopLocalLabel;
@property (nonatomic, strong)UILabel * infoLocalLabel;
@property (nonatomic, strong)UILabel * shopTypeLabel;
@property (nonatomic, strong)UILabel * shopTelLabel;
@property (nonatomic, strong)UILabel * shopInfoLabel;
@property (nonatomic, strong)UILabel * shopAlbumLabel;
@property (nonatomic, strong)UILabel * nameLabel;
@property (nonatomic, strong)UILabel * IDCardLabel;
@property (nonatomic, strong)UILabel * shopPictureLabel;
@property (nonatomic, strong)UILabel * cleanPictureLabel;
@property (nonatomic, strong)UILabel * IDCardPictureLabel;
@property (nonatomic, strong)UIButton * addButton;
@property (nonatomic, strong)UIButton * shopPictureButton;
@property (nonatomic, strong)UIButton * cleanPictureButton;
@property (nonatomic, strong)UIButton * frontIDCardButton;
@property (nonatomic, strong)UIButton * contraryIDCardButton;

@property (nonatomic, strong)UITextField * infoLocalTextField;
@property (nonatomic, strong)UITextField * shopNameTextField;
@property (nonatomic, strong)UITextField * shopTelTextField;
@property (nonatomic, strong)UITextField * nameTextField;
@property (nonatomic, strong)UITextField * IDCardTextField;

@property (nonatomic, weak)UITextView * infoTextView;

@property (nonatomic, strong)UIButton * localButton;
@property (nonatomic, strong)UIButton * typeButton;

@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, strong)UILabel * fourLabel;
@property (nonatomic, strong)UILabel * fiveLabel;
@property (nonatomic, strong)UILabel * sixLabel;
@property (nonatomic, strong)UILabel * sevenLabel;
@property (nonatomic, strong)UILabel * eightLabel;
@property (nonatomic, strong)UILabel * nineLabel;
@property (nonatomic, strong)UILabel * tenLabel;
@property (nonatomic, strong)UILabel * twelveLabel;

@property (nonatomic, weak)UIButton * agreeButton;
@property (nonatomic, weak)UIButton * sureButton;


@property (nonatomic, copy)NSString * type;
@property (nonatomic, copy)NSString * typeid;
@property (nonatomic, strong)NSArray * dataArray;
@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)UIPickerView * pickerView;

@property (nonatomic, copy)NSString * pictureType;
@property (nonatomic, copy)NSString * add_img;
@property (nonatomic, copy)NSString * merchants_business_license_img;
@property (nonatomic, copy)NSString * merchants_health_license_img;
@property (nonatomic, copy)NSString * merchants_user_id_card_front_img;
@property (nonatomic, copy)NSString * merchants_user_id_card_contrary_img;
@property (nonatomic, copy)NSString * longitude;
@property (nonatomic, copy)NSString * latitude;

@property (nonatomic, assign)BOOL isShow;
@property (nonatomic, copy)NSString * chooseTimeType;
@property (nonatomic, weak)UIView * shopTimeView;
@property (nonatomic, weak)UILabel * timeShowLabel;
@property (nonatomic, weak)UIImageView * downImageView;
@property (nonatomic, weak)UILabel * toLabel;
@property (nonatomic, strong)UILabel * shopTimeLabel;
@property (nonatomic, strong)UILabel * dateLabel;
@property (nonatomic, strong)UILabel * timeLabel;
@property (nonatomic, strong)UILabel * elevenLabel;
@property (nonatomic, strong)UIButton * workDayButton;
@property (nonatomic, strong)UIButton * weekDayButton;
@property (nonatomic, strong)UIButton * everyDayButton;
@property (nonatomic, strong)UIButton * timeStartButton;
@property (nonatomic, strong)UIButton * timeEndButton;
@property (nonatomic, strong)UIButton * timeSureButton;

@end

@implementation ApplyforShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _imagePickerController = [[UIImagePickerController alloc] init];
    _imagePickerController.delegate = self;
    _imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    _imagePickerController.allowsEditing = NO;
    
    
    _typeIndex = 0;
    self.isShow = NO;
    [self loadData];
    [self setupNav];
    [self setupUI];
    [self setupAlertVC];
    [self setupPivkerView];
}

- (void)loadData{
    
    [[ZRNetworkTool sharedTool] getCategoryResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            self.dataArray = responseData[@"data"];
            
            [self.pickerView reloadAllComponents];
        }
    }];
}

- (void)setupNav{
    
    if (self.dict) {
        
        self.title = @"店铺信息";
    }else{
        
       self.title = @"申请入驻";
    }
    
    
//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back(1)"] style:UIBarButtonItemStylePlain target:nil action:nil];
//    
//    self.navigationItem.backBarButtonItem = backItem;
}


- (void)setupUI{
    
    self.view.backgroundColor = ColorWithRGB(0xEFF0F1);
    
    UIScrollView * scrollView = [[UIScrollView alloc]init];
    
    self.scrollView = scrollView;
    
    [self.view addSubview:self.scrollView];
    
    UIView * container = [UIView new];
    
    self.container = container;
    
    [scrollView addSubview:self.container];
    
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(10 * SCREENH6, 10 * SCREENH6, 345 * SCREENH6, 635 * SCREENH6)];
    
    self.topView.backgroundColor = ZRWhiteColor;
    self.topView.layer.cornerRadius = 5;
    self.topView.layer.masksToBounds = YES;
    self.topView.userInteractionEnabled = YES;
    
    [self.scrollView addSubview:self.topView];
    
    
    self.bottomView = [self setupView];
    [self.scrollView addSubview:self.bottomView];
    
    self.shopNameLabel = [self setupLabelWithTitle:@"门店名字"];
    [self.topView addSubview:self.shopNameLabel];
    self.oneLabel = [self setupSymbolString];
    [self.topView addSubview:self.oneLabel];
    self.shopLocalLabel = [self setupLabelWithTitle:@"门店地址"];
    [self.topView addSubview:self.shopLocalLabel];
    self.twoLabel = [self setupSymbolString];
    [self.topView addSubview:self.twoLabel];
    self.infoLocalLabel = [self setupLabelWithTitle:@"详细地址"];
    [self.topView addSubview:self.infoLocalLabel];
    self.nineLabel = [self setupSymbolString];
    [self.topView addSubview:self.nineLabel];
    self.shopTypeLabel = [self setupLabelWithTitle:@"商户类型"];
    [self.topView addSubview:self.shopTypeLabel];
    self.threeLabel = [self setupSymbolString];
    [self.topView addSubview:self.threeLabel];
    self.shopTelLabel = [self setupLabelWithTitle:@"联系电话"];
    [self.topView addSubview:self.shopTelLabel];
    self.fourLabel = [self setupSymbolString];
    [self.topView addSubview:self.fourLabel];
    self.shopInfoLabel = [self setupLabelWithTitle:@"门店简介"];
    [self.topView addSubview:self.shopInfoLabel];
    self.shopTimeLabel = [self setupLabelWithTitle:@"营业时间"];
    [self.topView addSubview:self.shopTimeLabel];
    self.elevenLabel = [self setupSymbolString];
    [self.topView addSubview:self.elevenLabel];
    self.shopAlbumLabel = [self setupLabelWithTitle:@"商户封面"];
    [self.topView addSubview:self.shopAlbumLabel];
    self.twelveLabel = [self setupSymbolString];
    [self.topView addSubview:self.twelveLabel];

    self.shopNameTextField = [self setupTextFieldWithTitle:@"请输入门店名字"];
    [self.topView addSubview:self.shopNameTextField];
    self.shopTelTextField = [self setupTextFieldWithTitle:@"请输入联系电话"];
    self.shopTelTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [self.topView addSubview:self.shopTelTextField];
    self.infoLocalTextField = [self setupTextFieldWithTitle:@"请输入店铺详细地址"];
    [self.topView addSubview:self.infoLocalTextField];
    
    self.localButton = [self setupButtonWithTitle:@"请选择选择地点"];
    [self.topView addSubview:self.localButton];
    self.typeButton = [self setupButtonWithTitle:@"请选择商户类型"];
    [self.topView addSubview:self.typeButton];

    // 创建营业时间View
    UIView * shopTimeView = [[UIView alloc] initWithFrame:CGRectMake(10 * SCREENH6, 367 * SCREENH6, 325 * SCREENH6, 30 * SCREENH6)];
    
    shopTimeView.userInteractionEnabled = YES;
    shopTimeView.backgroundColor = ColorWithRGB(0xEFF0F1);
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [shopTimeView addGestureRecognizer:tapGR];
    shopTimeView.layer.cornerRadius = 5 * SCREENH6;
    shopTimeView.layer.masksToBounds = YES;
    
    self.shopTimeView = shopTimeView;
    
    [self.topView addSubview:self.shopTimeView];
    
    UILabel * timeShowLabel = [UILabel new];
    
    timeShowLabel.textColor = [UIColor lightGrayColor];
    timeShowLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    timeShowLabel.text = @"请选择营业时间";
    timeShowLabel.textAlignment = NSTextAlignmentCenter;
    
    self.timeShowLabel = timeShowLabel;
    
    [self.shopTimeView addSubview:self.timeShowLabel];
    
    
    UIImageView * downImageView = [UIImageView new];
    
    downImageView.image = [UIImage imageNamed:@"多边形1"];
    
    self.downImageView = downImageView;
    
    [self.shopTimeView addSubview:self.downImageView];
    
    
    UILabel * dateLabel = [UILabel new];
    
    dateLabel.textColor = ZRBlackColor;
    dateLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    dateLabel.text = @"日期";
    dateLabel.hidden = YES;
    
    self.dateLabel = dateLabel;
    
    [self.shopTimeView addSubview:self.dateLabel];
    
    
    UILabel * timeLabel = [UILabel new];
    
    timeLabel.textColor = ZRBlackColor;
    timeLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    timeLabel.text = @"时间";
    timeLabel.hidden = YES;
    
    self.timeLabel = timeLabel;
    
    [self.shopTimeView addSubview:self.timeLabel];
    
    self.workDayButton = [self setupShopTimeWithTitle:@"工作日"];
    self.workDayButton.selected = YES;
    [self.shopTimeView addSubview:self.workDayButton];
    self.weekDayButton = [self setupShopTimeWithTitle:@"周日"];
    [self.shopTimeView addSubview:self.weekDayButton];
    self.everyDayButton = [self setupShopTimeWithTitle:@"每天"];
    [self.shopTimeView addSubview:self.everyDayButton];

//    setupChooseTimeWithTitle
    self.timeStartButton = [self setupChooseTimeWithTitle:@"开始"];
    [self.shopTimeView addSubview:self.timeStartButton];
    self.timeEndButton = [self setupChooseTimeWithTitle:@"结束"];
    [self.shopTimeView addSubview:self.timeEndButton];
    
    UILabel * toLabel = [UILabel new];
    
    toLabel.textColor = [UIColor lightGrayColor];
    toLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    toLabel.text = @"至";
    toLabel.hidden = YES;
    
    self.toLabel = toLabel;
    
    [self.shopTimeView addSubview:self.toLabel];
    
    
    UIButton * timeSureButton = [UIButton new];
    
    [timeSureButton setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [timeSureButton setTitle:@"确定" forState:UIControlStateNormal];
    [timeSureButton setBackgroundColor:ZRBlackColor];
    timeSureButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    timeSureButton.layer.cornerRadius = 5 * SCREENH6;
    timeSureButton.layer.masksToBounds = YES;
    [timeSureButton addTarget:self action:@selector(clickTiemSureButton) forControlEvents:UIControlEventTouchUpInside];
    timeSureButton.hidden = YES;
    
    self.timeSureButton = timeSureButton;
    
    [self.shopTimeView addSubview:self.timeSureButton];
    
    // 创建textView
    UITextView * infoTextView =[[UITextView alloc] init];
    
    infoTextView.backgroundColor= ColorWithRGB(0xEFF0F1);
    infoTextView.text = @"请输入门店简介...";
    infoTextView.font = [UIFont systemFontOfSize:14 * SCREENH6];
    infoTextView.textColor = ColorWithRGB(0xbebebe);
    infoTextView.delegate = self;
    
    self.infoTextView = infoTextView;
    [self.topView addSubview:self.infoTextView];
    
//    AddShopPicture * addView = [[AddShopPicture alloc] initWithFrame:CGRectMake(0, 480 * SCREENH6, 325 * SCREENH6, 70 * SCREENH6)];
//    addView.addShopPictureDelegate = self;
//
//    self.pictureView = addView;
//
//    [self.topView addSubview:self.pictureView];
    self.addButton = [self setupButton];
    [self.topView addSubview:self.addButton];
    
    self.nameLabel = [self setupLabelWithTitle:@"经营者真实姓名"];
    [self.bottomView addSubview:self.nameLabel];
    self.fiveLabel = [self setupSymbolString];
    [self.bottomView addSubview:self.fiveLabel];
    self.IDCardLabel = [self setupLabelWithTitle:@"经营者身份证号"];
    [self.bottomView addSubview:self.IDCardLabel];
    self.sixLabel = [self setupSymbolString];
    [self.bottomView addSubview:self.sixLabel];
    self.shopPictureLabel = [self setupLabelWithTitle:@"上传营业执照"];
    [self.bottomView addSubview:self.shopPictureLabel];
    self.sevenLabel = [self setupSymbolString];
    [self.bottomView addSubview:self.sevenLabel];
    self.cleanPictureLabel = [self setupLabelWithTitle:@"上传卫生许可证"];
    [self.bottomView addSubview:self.cleanPictureLabel];
    self.IDCardPictureLabel = [self setupLabelWithTitle:@"上传经营者身份证"];
    [self.bottomView addSubview:self.IDCardPictureLabel];
    self.eightLabel = [self setupSymbolString];
    [self.bottomView addSubview:self.eightLabel];
    self.shopPictureButton = [self setupButton];
    [self.bottomView addSubview:self.shopPictureButton];
    self.cleanPictureButton = [self setupButton];
    [self.bottomView addSubview:self.cleanPictureButton];
    self.frontIDCardButton = [self setupButton];
    [self.bottomView addSubview:self.frontIDCardButton];
    self.contraryIDCardButton = [self setupButton];
    [self.bottomView addSubview:self.contraryIDCardButton];
    
    self.nameTextField = [self setupTextFieldWithTitle:@"请输入经营者真实姓名"];
    [self.bottomView addSubview:self.nameTextField];
    self.IDCardTextField = [self setupTextFieldWithTitle:@"请输入经营者身份证号码"];
    self.IDCardTextField.keyboardType = UIKeyboardTypeDecimalPad;
    [self.bottomView addSubview:self.IDCardTextField];
    
    UIButton * agreeButton = [UIButton new];
    
    [agreeButton setTitle:@" 同意商户合作协议" forState:UIControlStateNormal];
    [agreeButton setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [agreeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [agreeButton setImage:[UIImage imageNamed:@"圆角矩形6拷贝"] forState:UIControlStateNormal];
    [agreeButton setImage:[UIImage imageNamed:@"绿色勾选"] forState:UIControlStateSelected];
    [agreeButton addTarget:self action:@selector(clickChooseModelButton:) forControlEvents:UIControlEventTouchUpInside];
    agreeButton.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.agreeButton = agreeButton;
    
    [self.scrollView addSubview:self.agreeButton];
    
    
    UIButton * sureButton = [UIButton new];
    
    [sureButton setTitle:@"提交审核" forState:UIControlStateNormal];
    [sureButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    [sureButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
    [sureButton setBackgroundImage:[UIImage imageNamed:@"提交审核"] forState:UIControlStateNormal];
    [sureButton setBackgroundImage:[UIImage imageNamed:@"提交审核_灰"] forState:UIControlStateDisabled];
    [sureButton addTarget:self action:@selector(clickSureButton) forControlEvents:UIControlEventTouchUpInside];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    sureButton.enabled = NO;
    
    self.sureButton = sureButton;
    
    [self.scrollView addSubview:self.sureButton];
    
    
    if (self.dict) {
//        NSLog(@"dict===%@",self.dict);
        self.shopNameTextField.text = self.dict[@"merchants_name"];
        self.shopTelTextField.text = self.dict[@"merchants_phone"];
        self.infoTextView.text = self.dict[@"merchants_info"];
        self.infoTextView.textColor = ZRBlackColor;
        self.nameTextField.text = self.dict[@"real_name"];
        self.IDCardTextField.text = [NSString stringWithFormat:@"%@",self.dict[@"id_card"]];
        NSString * merchants_address = self.dict[@"merchants_address"];
        NSArray * array = [merchants_address componentsSeparatedByString:@","];
        [self.localButton setTitle:array.firstObject forState:UIControlStateNormal];
        self.localButton.selected = YES;
        self.infoLocalTextField.text = array.lastObject;
        [self.typeButton setTitle:self.dict[@"merchants_category_name"] forState:UIControlStateNormal];
        self.typeButton.selected = YES;
        self.typeid = [NSString stringWithFormat:@"%@",self.dict[@"merchants_category"]];
        self.merchants_business_license_img = self.dict[@"merchants_business_license_img"];
        if (self.merchants_business_license_img.length > 0) {
            
            NSString * merchants_business = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.merchants_business_license_img];
            NSURL * merchants_business_URL = [NSURL URLWithString:merchants_business];
            [self.shopPictureButton sd_setImageWithURL:merchants_business_URL forState:UIControlStateNormal];
        }else{
            
            [self.shopPictureButton setImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
        }
       
        NSString * merchants_user_id_card_img = self.dict[@"merchants_user_id_card_img"];
        NSArray * id_card_array = [merchants_user_id_card_img componentsSeparatedByString:@","];
        self.merchants_user_id_card_front_img = id_card_array.firstObject;
        self.merchants_user_id_card_contrary_img = id_card_array.lastObject;
        NSString * id_card_front_img = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.merchants_user_id_card_front_img];
        NSString * id_card_contrary_img = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.merchants_user_id_card_contrary_img];
        NSURL * id_card_front_img_URL = [NSURL URLWithString:id_card_front_img];
        NSURL * id_card_contrary_img_URL = [NSURL URLWithString:id_card_contrary_img];
        [self.frontIDCardButton sd_setImageWithURL:id_card_front_img_URL forState:UIControlStateNormal];
        [self.contraryIDCardButton sd_setImageWithURL:id_card_contrary_img_URL forState:UIControlStateNormal];
        
        self.merchants_health_license_img = self.dict[@"merchants_health_license_img"];
        if (self.merchants_health_license_img.length > 0) {
            NSString * merchants_health = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.merchants_health_license_img];
            NSURL * merchants_health_URL = [NSURL URLWithString:merchants_health];
            [self.cleanPictureButton sd_setImageWithURL:merchants_health_URL forState:UIControlStateNormal];
        }else{
            
            [self.cleanPictureButton setImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
        }
        
        self.add_img = self.dict[@"merchants_img"];
        NSString * add_img = [NSString stringWithFormat:@"%@%@",BASEURLSTR,self.add_img];
        NSURL * add_url = [NSURL URLWithString:add_img];
        [self.addButton sd_setImageWithURL:add_url forState:UIControlStateNormal];
        self.latitude = [NSString stringWithFormat:@"%@",self.dict[@"merchants_latitude"]];
        self.longitude = [NSString stringWithFormat:@"%@",self.dict[@"merchants_longitude"]];
        self.timeShowLabel.text = self.dict[@"merchants_open_time"];
        self.timeShowLabel.textColor = ZRBlackColor;
        NSArray * dateArray = [self.timeShowLabel.text componentsSeparatedByString:@" "];
        NSString * weekStr = dateArray.firstObject;
        if ([weekStr isEqualToString:self.workDayButton.titleLabel.text]) {
            
            self.workDayButton.selected = YES;
            self.weekDayButton.selected = NO;
            self.everyDayButton.selected = NO;
        }else if ([weekStr isEqualToString:self.weekDayButton.titleLabel.text]){
            
            self.workDayButton.selected = NO;
            self.weekDayButton.selected = YES;
            self.everyDayButton.selected = NO;
        }else if ([weekStr isEqualToString:self.everyDayButton.titleLabel.text]){
            
            self.workDayButton.selected = NO;
            self.weekDayButton.selected = NO;
            self.everyDayButton.selected = YES;
        }
        
        NSArray * timeArray = [dateArray.lastObject componentsSeparatedByString:@"-"];
        
        [self.timeStartButton setTitle:timeArray.firstObject forState:UIControlStateNormal];
        [self.timeEndButton setTitle:timeArray.lastObject forState:UIControlStateNormal];
        self.timeEndButton.selected = YES;
        self.timeStartButton.selected = YES;
    }
}


- (void)viewDidLayoutSubviews{
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
 
//    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.scrollView).offset(15 * SCREENH6);
//        make.trailing.mas_equalTo(self.scrollView).offset(-15 * SCREENH6);
//        make.top.mas_equalTo(self.scrollView).offset(10 * SCREENH6);
//        make.height.mas_equalTo(560 * SCREENH6);
//    }];
    
    [self.shopNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.topView).offset(10 * SCREENH6);
        make.top.mas_equalTo(self.topView).offset(15 * SCREENH6);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopNameLabel.mas_trailing);
        make.top.mas_equalTo(self.shopNameLabel);
    }];
    
    [self.shopNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopNameLabel);
        make.trailing.mas_equalTo(self.topView).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.shopNameLabel.mas_bottom).offset(3 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.shopLocalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopNameLabel);
        make.top.mas_equalTo(self.shopNameTextField.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopLocalLabel.mas_trailing);
        make.top.mas_equalTo(self.shopLocalLabel);
    }];
    
    [self.localButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.shopNameTextField);
        make.top.mas_equalTo(self.shopLocalLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.infoLocalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopLocalLabel);
        make.top.mas_equalTo(self.localButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.nineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.infoLocalLabel.mas_trailing);
        make.top.mas_equalTo(self.infoLocalLabel);
    }];
    
    [self.infoLocalTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.localButton);
        make.top.mas_equalTo(self.infoLocalLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.shopTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.infoLocalLabel);
        make.top.mas_equalTo(self.infoLocalTextField.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTypeLabel.mas_trailing);
        make.top.mas_equalTo(self.shopTypeLabel);
    }];
    
    [self.typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.infoLocalTextField);
        make.top.mas_equalTo(self.shopTypeLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.shopTelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTypeLabel);
        make.top.mas_equalTo(self.typeButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.fourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTelLabel.mas_trailing);
        make.top.mas_equalTo(self.shopTelLabel);
    }];
    
    [self.shopTelTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.typeButton);
        make.top.mas_equalTo(self.shopTelLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.shopTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTelLabel);
        make.top.mas_equalTo(self.shopTelTextField.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.elevenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTimeLabel.mas_trailing);
        make.top.mas_equalTo(self.shopTimeLabel);
    }];
    
    [self.timeShowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.shopTimeView);
        make.centerX.mas_equalTo(self.shopTimeView);
    }];
    
    [self.downImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.shopTimeView).offset(12 * SCREENH6);
        make.trailing.mas_equalTo(self.shopTimeView).mas_offset(-5 * SCREENH6);
        make.width.mas_equalTo(9 * SCREENH6);
        make.height.mas_equalTo(6 * SCREENH6);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.mas_equalTo(self.shopTimeView).offset(10 * SCREENH6);
    }];
    
    [self.workDayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.dateLabel);
        make.top.mas_equalTo(self.dateLabel.mas_bottom).offset(10 * SCREENH6);
        make.width.mas_equalTo(50 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.weekDayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.workDayButton);
        make.leading.mas_equalTo(self.workDayButton.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.everyDayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.weekDayButton);
        make.leading.mas_equalTo(self.weekDayButton.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.everyDayButton.mas_bottom).offset(15 * SCREENH6);
        make.leading.mas_equalTo(self.dateLabel);
    }];
    
    [self.timeStartButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.timeLabel);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10 * SCREENH6);
        make.width.mas_equalTo(60 * SCREENH6);
        make.height.mas_equalTo(25 * SCREENH6);
    }];
    
    [self.toLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeStartButton);
        make.leading.mas_equalTo(self.timeStartButton.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.timeEndButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.timeStartButton);
        make.leading.mas_equalTo(self.toLabel.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.timeSureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.shopTimeView);
        make.top.mas_equalTo(self.timeStartButton.mas_bottom).offset(15 * SCREENH6);
        make.width.mas_equalTo(60 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.shopInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopTimeLabel);
        make.top.mas_equalTo(self.shopTimeView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.infoTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.shopTelTextField);
        make.height.mas_equalTo(70 * SCREENH6);
        make.top.mas_equalTo(self.shopInfoLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.shopAlbumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopInfoLabel);
        make.top.mas_equalTo(self.infoTextView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.twelveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopAlbumLabel.mas_trailing);
        make.top.mas_equalTo(self.shopAlbumLabel);
    }];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopAlbumLabel);
        make.top.mas_equalTo(self.shopAlbumLabel.mas_bottom).offset(10 * SCREENH6);
        make.height.mas_equalTo(60 * SCREENH6);
        make.width.mas_equalTo(77 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.topView);
        make.height.mas_equalTo(455 * SCREENH6);
        make.top.mas_equalTo(self.topView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopAlbumLabel);
        make.top.mas_equalTo(self.bottomView).offset(15 * SCREENH6);
    }];
    
    [self.fiveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel.mas_trailing);
        make.top.mas_equalTo(self.nameLabel);
    }];
    
    [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.shopTelTextField);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.IDCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.nameTextField.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.sixLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.IDCardLabel.mas_trailing);
        make.top.mas_equalTo(self.IDCardLabel);
    }];
    
    [self.IDCardTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.nameTextField);
        make.top.mas_equalTo(self.IDCardLabel.mas_bottom).offset(3 * SCREENH6);
    }];
    
    [self.shopPictureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.IDCardLabel);
        make.top.mas_equalTo(self.IDCardTextField.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.sevenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopPictureLabel.mas_trailing);
        make.top.mas_equalTo(self.shopPictureLabel);
    }];
    
    [self.shopPictureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopPictureLabel);
        make.top.mas_equalTo(self.shopPictureLabel.mas_bottom).offset(5 * SCREENH6);
        make.height.mas_equalTo(60 * SCREENH6);
        make.width.mas_equalTo(77 * SCREENH6);
    }];
    
    [self.cleanPictureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopPictureButton);
        make.top.mas_equalTo(self.shopPictureButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.cleanPictureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.width.mas_equalTo(self.shopPictureButton);
        make.top.mas_equalTo(self.cleanPictureLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.IDCardPictureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.cleanPictureButton);
        make.top.mas_equalTo(self.cleanPictureButton.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.eightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.IDCardPictureLabel.mas_trailing);
        make.top.mas_equalTo(self.IDCardPictureLabel);
    }];
    
    [self.frontIDCardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.height.width.mas_equalTo(self.cleanPictureButton);
        make.top.mas_equalTo(self.IDCardPictureLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.contraryIDCardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.frontIDCardButton);
        make.leading.mas_equalTo(self.frontIDCardButton.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.bottomView);
        make.top.mas_equalTo(self.bottomView.mas_bottom).offset(15 * SCREENH6);
    }];

    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.scrollView);
        make.height.mas_equalTo(40 * SCREENH6);
        make.width.mas_equalTo(258 * SCREENH6);
        make.top.mas_equalTo(self.agreeButton.mas_bottom).offset(30 * SCREENH6);
        make.bottom.mas_equalTo(self.container).offset(-20 * SCREENH6);
    }];
}


- (void)setupAlertVC{
    
    self.alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"选择照片方式" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * camerAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * albumsAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [self.alertVC addAction:camerAction];
    [self.alertVC addAction:albumsAction];
    [self.alertVC addAction:cancelAction];
    
}

#pragma mark -实现图片选择器代理-（上传图片的网络请求也是在这个方法里面进行，这里我不再介绍具体怎么上传图片）
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //通过key值获取到图片
    //给UIimageView赋值已经选择的相片
    NSData *frontImageData = UIImageJPEGRepresentation(image,0.5);
    NSString *base64Data = [frontImageData base64EncodedStringWithOptions:0];
    NSString * reslut = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",base64Data];
    
    if ([self.pictureType isEqualToString:@"add"]) {

        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                [self.addButton setImage:image forState:UIControlStateNormal];
                self.add_img = [NSString stringWithFormat:@"%@",responseData[@"data"]];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
        
    }else if ([self.pictureType isEqualToString:@"shopPicture"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                [self.shopPictureButton setImage:image forState:UIControlStateNormal];
                self.merchants_business_license_img = [NSString stringWithFormat:@"%@",responseData[@"data"]];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }else if ([self.pictureType isEqualToString:@"cleanPicture"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                [self.cleanPictureButton setImage:image forState:UIControlStateNormal];
                self.merchants_health_license_img = [NSString stringWithFormat:@"%@",responseData[@"data"]];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
        
    }else if ([self.pictureType isEqualToString:@"frontPicture"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                [self.frontIDCardButton setImage:image forState:UIControlStateNormal];
                self.merchants_user_id_card_front_img = [NSString stringWithFormat:@"%@",responseData[@"data"]];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
        
    }else if ([self.pictureType isEqualToString:@"contraryPicture"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                [self.contraryIDCardButton setImage:image forState:UIControlStateNormal];
                self.merchants_user_id_card_contrary_img = [NSString stringWithFormat:@"%@",responseData[@"data"]];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }
    
    
    //上传图片到服务器--在这里进行图片上传的网络请求，这里不再介绍
    
}

//当用户取消选择的时候，调用该方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}


- (UIButton *)setupButton{
    
    UIButton * button = [UIButton new];
    
    [button setImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickAddPicture:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

- (UIButton *)setupButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    //    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    button.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    [button setBackgroundColor:ColorWithRGB(0xEFF0F1)];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [button addTarget:self action:@selector(clickLocalButton:) forControlEvents:UIControlEventTouchUpInside];
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    
    return button;
}


- (UIButton *)setupShopTimeWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setBackgroundImage:[UIImage imageNamed:@"日期选择"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"日期选中"] forState:UIControlStateSelected];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    [button addTarget:self action:@selector(chooseWeekDay:) forControlEvents:UIControlEventTouchUpInside];
    button.hidden = YES;
    
    return button;
}

- (UIButton *)setupChooseTimeWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setBackgroundColor:ZRWhiteColor];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateSelected];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    [button addTarget:self action:@selector(ChooseTime:) forControlEvents:UIControlEventTouchUpInside];
    button.hidden = YES;
    
    return button;
}


- (UITextField *)setupTextFieldWithTitle:(NSString *)string{
    
    UITextField * textField = [UITextField new];
    
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.backgroundColor = ColorWithRGB(0xEDEEEF);
    
    //设置光标颜色
    textField.tintColor = ZRBlackColor;
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:14 * SCREENH6];
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:string attributes:attrs];
    textField.font = [UIFont systemFontOfSize:14 * SCREENH6];
    textField.textColor = ZRBlackColor;
    textField.textAlignment = NSTextAlignmentCenter;
    textField.delegate = self;
    
    return textField;
}

- (UILabel *)setupLabelWithTitle:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.text = title;
    label.textColor = ZRBlackColor;
    label.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    return label;
}


- (UILabel *)setupSymbolString{
    
    UILabel * label = [UILabel new];
    
    label.textColor = [UIColor redColor];
    label.text = @"*";
    label.font = [UIFont systemFontOfSize:10 * SCREENH6];
    
    return label;
}


- (UIView *)setupView{
    
    UIView * view = [UIView new];
    
    view.backgroundColor = ZRWhiteColor;
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    view.userInteractionEnabled = YES;
    
    return view;
}

- (void)clickChooseModelButton:(UIButton *)button{
    
    button.selected = !button.selected;
    
    [self reloadButtonState];
}


- (void)setupPivkerView{
    
    self.bgView = [[UIView alloc]init];
    self.bgView.frame = CGRectMake(0, kScreenH, kScreenW, kScreenH / 3);
    self.bgView.backgroundColor = ZRWhiteColor;
    [self.view addSubview:self.bgView];
    
    UIView *btnView = [[UIView alloc]init];
    btnView.frame = CGRectMake(0, 0, kScreenW, 40 * SCREENH6);
    btnView.backgroundColor = ColorWithRGB(0xababab);
    [self.bgView addSubview:btnView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(10 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [sureBtn setTitle:@"取消" forState:UIControlStateNormal];
    [sureBtn setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:sureBtn];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(self.view.frame.size.width - 70 * SCREENH6, 5 * SCREENH6, 60 * SCREENH6, 30 * SCREENH6);
    [cancelBtn setTitle:@"确定" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(sureBtn) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:cancelBtn];
    
    float height = kScreenH / 3 - 40 * SCREENH6;
    self.pickerView = [[UIPickerView alloc]init];
    self.pickerView.frame = CGRectMake(0, 40 * SCREENH6, kScreenW, height);
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    [self.bgView addSubview:self.pickerView];
}


// 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// 每列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return self.dataArray.count;
}


// 返回每一行的内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    
    NSDictionary * dict = self.dataArray[row];

    NSString * bankInfo = [NSString stringWithFormat:@"%@",dict[@"name"]];
    
    return bankInfo;
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
   _typeIndex = row;
}


- (void)cancelBtn{
    
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgView.frame = CGRectMake(0, self.view.frame.size.height, kScreenW, kScreenH / 3);
    } completion:^(BOOL finished) {
    }];
    
}


- (void)sureBtn{
    
    NSDictionary * dict = self.dataArray[_typeIndex];
    
    NSString * type = dict[@"name"];
    self.typeid = dict[@"id"];
    
    [self.typeButton setTitle:type forState:UIControlStateNormal];
    self.typeButton.selected = YES;
    
    [self reloadButtonState];
    
    [UIView animateWithDuration:0.5 animations:^{
        self.bgView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, kScreenH / 3);
    } completion:^(BOOL finished) {
    }];
}




#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"请输入门店简介...";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"请输入门店简介..."]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}

- (void)clickAddPicture:(UIButton *)button{
    
    if (button == self.shopPictureButton) {
        
        self.pictureType = @"shopPicture";
    }else if (button == self.cleanPictureButton){
        
        self.pictureType = @"cleanPicture";
    }else if (button == self.frontIDCardButton){
        
        self.pictureType = @"frontPicture";
    }else if (button == self.contraryIDCardButton){
        
        self.pictureType = @"contraryPicture";
    }else if (button == self.addButton){
        
        self.pictureType = @"add";
    }
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
        self.alertVC.popoverPresentationController.sourceView = self.view;
        self.alertVC.popoverPresentationController.sourceRect = CGRectMake(10 * SCREENH6,kScreenH - 150 * SCREENH6,355 * SCREENH6,150 * SCREENH6);
        //            self.alertVC.modalPresentationStyle = UIModalPresentationFormSheet;
    }
    
    [self presentViewController:self.alertVC animated:YES completion:nil];
}

- (void)clickItemButton:(NSInteger )tag{
    
    self.count = tag;
    self.pictureType = @"addView";
    
    [self presentViewController:self.alertVC animated:YES completion:nil];
}

- (void)clickLocalButton:(UIButton *)button{
    
    if(button == self.typeButton){
        
        [self.shopTelTextField resignFirstResponder];
        [self.infoLocalTextField resignFirstResponder];
        [self.shopNameTextField resignFirstResponder];
        [self.shopTelTextField resignFirstResponder];
        [self.nameTextField resignFirstResponder];
        [self.IDCardTextField resignFirstResponder];
        
        [UIView animateWithDuration:0.5 animations:^{
            self.bgView.frame = CGRectMake(0, kScreenH - kScreenH / 3, kScreenW, kScreenH / 3);
        }];
    }else if (button == self.localButton){
        
        HiddenBar;
        
        ShopLocalViewController * localVC = [ShopLocalViewController new];
        
        [self.navigationController pushViewController:localVC animated:YES];
        
        [localVC returnLocalName:^(NSDictionary *localInfo) {
            
            NSString * name = localInfo[@"name"];
            self.longitude = localInfo[@"longitude"];
            self.latitude = localInfo[@"latitude"];
            
            [self.localButton setTitle:name forState:UIControlStateNormal];
            self.localButton.selected = YES;
            
            [self reloadButtonState];
        }];
    }
    
}


- (void)clickSureButton{
    
    ShowHUD;
    //获取当前时间日期
    NSDate *date=[NSDate date];
    NSDateFormatter *format1=[[NSDateFormatter alloc] init];
    [format1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateStr;
    dateStr=[format1 stringFromDate:date];

    NSString * infoText;
    if ([self.infoTextView.text isEqualToString:@"请输入门店简介..."]) {

        infoText = @"";
    }else{

        infoText = self.infoTextView.text;
    }

    NSString * cleanImg;
    if (self.merchants_health_license_img) {

        cleanImg = self.merchants_health_license_img;
    }else{

        cleanImg = @"";
    }

    NSString * user_id = DEF_GET_OBJECT(@"id");
    NSString * merchants_user_id_card_img = [NSString stringWithFormat:@"%@,%@",self.merchants_user_id_card_front_img,self.merchants_user_id_card_contrary_img];
    NSString * shop_id = DEF_GET_OBJECT(@"shopid");
    NSString * adress = [NSString stringWithFormat:@"%@,%@",self.localButton.titleLabel.text,self.infoLocalTextField.text];

    if (self.dict) {

        NSDictionary * dict = @{@"merchants_name":self.shopNameTextField.text,@"merchants_category":self.typeid,@"merchants_address":adress,@"merchants_longitude":self.longitude,@"merchants_latitude":self.latitude,@"merchants_info":infoText,@"merchants_img":self.add_img,@"merchants_health_license_img":cleanImg,@"merchants_user_id":user_id,@"real_name":self.nameTextField.text,@"id_card":self.IDCardTextField.text,@"merchants_phone":self.shopTelTextField.text,@"merchants_user_id_card_img":merchants_user_id_card_img,@"merchants_business_license_img":self.merchants_business_license_img,@"timeStamp":dateStr,@"id":shop_id,@"merchants_open_time":self.timeShowLabel.text};

        NSString * sign = [self signStr:dict];

        NSDictionary * paraDict = @{@"merchants_name":self.shopNameTextField.text,@"merchants_category":self.typeid,@"merchants_address":adress,@"merchants_longitude":self.longitude,@"merchants_latitude":self.latitude,@"merchants_info":infoText,@"merchants_img":self.add_img,@"merchants_health_license_img":cleanImg,@"merchants_user_id":user_id,@"real_name":self.nameTextField.text,@"id_card":self.IDCardTextField.text,@"merchants_phone":self.shopTelTextField.text,@"merchants_user_id_card_img":merchants_user_id_card_img,@"merchants_business_license_img":self.merchants_business_license_img,@"timeStamp":dateStr,@"sign":sign,@"id":shop_id,@"merchants_open_time":self.timeShowLabel.text};

        [[NetworkTool sharedTools] POST:@"/Api/editMerchants" parameters:paraDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

            HiddenHUD;

            int code = [responseObject[@"code"] intValue];

            if (code == 200) {

                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseObject[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];

                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {

                                                                          [self.navigationController popViewControllerAnimated:YES];
                                                                      }];

                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{

                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseObject[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];

                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {


                                                                      }];

                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            HiddenHUD;
        }];

    }else{

        NSDictionary * dict = @{@"merchants_name":self.shopNameTextField.text,@"merchants_category":self.typeid,@"merchants_address":adress,@"merchants_longitude":self.longitude,@"merchants_latitude":self.latitude,@"merchants_info":infoText,@"merchants_img":self.add_img,@"merchants_health_license_img":cleanImg,@"merchants_user_id":user_id,@"real_name":self.nameTextField.text,@"id_card":self.IDCardTextField.text,@"merchants_phone":self.shopTelTextField.text,@"merchants_user_id_card_img":merchants_user_id_card_img,@"merchants_business_license_img":self.merchants_business_license_img,@"timeStamp":dateStr,@"merchants_open_time":self.timeShowLabel.text};

        NSString * sign = [self signStr:dict];

        NSDictionary * paraDict = @{@"merchants_name":self.shopNameTextField.text,@"merchants_category":self.typeid,@"merchants_address":adress,@"merchants_longitude":self.longitude,@"merchants_latitude":self.latitude,@"merchants_info":infoText,@"merchants_img":self.add_img,@"merchants_health_license_img":cleanImg,@"merchants_user_id":user_id,@"real_name":self.nameTextField.text,@"id_card":self.IDCardTextField.text,@"merchants_phone":self.shopTelTextField.text,@"merchants_user_id_card_img":merchants_user_id_card_img,@"merchants_business_license_img":self.merchants_business_license_img,@"timeStamp":dateStr,@"sign":sign,@"merchants_open_time":self.timeShowLabel.text};

        [[NetworkTool sharedTools] POST:@"Api/joinMerchants" parameters:paraDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

            HiddenHUD;

            int code = [responseObject[@"code"] intValue];

            if (code == 200) {

                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseObject[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];

                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {

                                                                          [self.navigationController popViewControllerAnimated:YES];
                                                                      }];

                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{

                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseObject[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];

                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {


                                                                      }];

                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }


        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            HiddenHUD;
        }];
    }
}


- (void)reloadButtonState{
    
    BOOL isFinish;
    
    if ([self.timeShowLabel.text isEqualToString:@"请选择营业时间"]) {
        
        isFinish = NO;
    }else{
        
        isFinish = YES;
    }
    
    if (self.nameTextField.text.length > 0 && self.localButton.selected && self.typeButton.selected && self.infoLocalTextField.text.length > 0 && self.shopTelTextField.text.length > 0 && self.shopNameTextField.text.length > 0 && self.IDCardTextField.text.length > 0 && self.merchants_business_license_img && self.merchants_user_id_card_front_img && self.merchants_user_id_card_contrary_img && self.agreeButton.selected && isFinish && self.add_img) {
        
        self.sureButton.enabled = YES;
    }else{
        
        self.sureButton.enabled = NO;
    }
}


- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    [self reloadButtonState];
}

- (void)setMerchants_user_id_card_front_img:(NSString *)merchants_user_id_card_front_img{
    
    _merchants_user_id_card_front_img = merchants_user_id_card_front_img;
    [self reloadButtonState];
}


- (void)setMerchants_user_id_card_contrary_img:(NSString *)merchants_user_id_card_contrary_img{
    
    _merchants_user_id_card_contrary_img = merchants_user_id_card_contrary_img;
    [self reloadButtonState];
}


- (void)setMerchants_business_license_img:(NSString *)merchants_business_license_img{
    
    _merchants_business_license_img = merchants_business_license_img;
    
    [self reloadButtonState];
}


- (NSString *)signStr:(NSDictionary *)dict{
    
    NSArray *keyArray = [dict allKeys];
    
    //定义一个排序数组，存储排序好之后的key值
    NSArray *sortArray = [keyArray sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2 options:NSNumericSearch];
    }];
    
    //这时我们再创建一个数组，来按升序存储key对应的Value，通过遍历sortArray的方法
    NSMutableArray *valueArray = [NSMutableArray array];
    for (NSString *sortString in sortArray) {
        [valueArray addObject:[dict objectForKey:sortString]];
    }
    //    现在我们有两个数组，分别对应升序排序的key和value，所以再创建一个keyValue的数组来存储每一个key和value的格式
    //    NSMutableArray *signArray = [NSMutableArray array];
    //    for (int i = 0; i < sortArray.count; i++) {
    //        NSString *keyValueStr = [NSString stringWithFormat:@"%@:%@",sortArray[i],valueArray[i]];
    //        [signArray addObject:keyValueStr];
    //    }
    
    //最后的一步，就是用“,”把每个字符串拼接起来
    NSString *sign = [valueArray componentsJoinedByString:@""];
    
    NSString * resStr = [NSString stringWithFormat:@"%@NDQ0NTlmMDk4MTU3NTg3NzFiZTFlZmQwNDFjNzA0ZGMyYWY0NzU5ZQ==",sign];
    
    NSString *signStr = [self md5:resStr];
    
    NSString * baseStr = [self encode:signStr];
    
    return baseStr;
}

- (NSString *) md5:(NSString *) str
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}

- (NSString *)encode:(NSString *)string
{
    //先将string转换成data
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    
    NSData *base64Data = [data base64EncodedDataWithOptions:0];
    
    NSString *baseString = [[NSString alloc]initWithData:base64Data encoding:NSUTF8StringEncoding];
    
    return baseString;
}


- (void)tapAction{
    
    if (self.isShow) {
        
        
    }else{
        
        self.isShow = YES;
    
        self.shopTimeView.height = 180 * SCREENH6;
        self.downImageView.image = [UIImage imageNamed:@"多边形1拷贝"];
        self.topView.height = 775 * SCREENH6;
        
        self.timeShowLabel.hidden = YES;
        self.dateLabel.hidden = NO;
        self.timeLabel.hidden = NO;
        self.workDayButton.hidden = NO;
        self.weekDayButton.hidden = NO;
        self.everyDayButton.hidden = NO;
        self.timeStartButton.hidden = NO;
        self.toLabel.hidden = NO;
        self.timeEndButton.hidden = NO;
        self.timeSureButton.hidden = NO;
    }
    
}


- (void)chooseWeekDay:(UIButton *)button{
    
    if (button == self.workDayButton) {
        
        if (!button.selected) {
            
            button.selected = YES;
            self.weekDayButton.selected = NO;
            self.everyDayButton.selected = NO;
        }
    }else if (button == self.weekDayButton) {
        
        if (!button.selected) {
            
            button.selected = YES;
            self.workDayButton.selected = NO;
            self.everyDayButton.selected = NO;
        }
    }else if (button == self.everyDayButton) {
        
        if (!button.selected) {
            
            button.selected = YES;
            self.weekDayButton.selected = NO;
            self.workDayButton.selected = NO;
        }
    }
}

- (void)ChooseTime:(UIButton *)button{
    
    if (button == self.timeStartButton) {
        
        self.chooseTimeType = @"start";
    }else{
        
        self.chooseTimeType = @"end";
    }
    
    [self presentDateController];
}


- (void)clickTiemSureButton{
    
    if (self.timeStartButton.selected && self.timeEndButton.selected) {
        
        self.isShow = NO;
        
        self.shopTimeView.height = 30 * SCREENH6;
        self.downImageView.image = [UIImage imageNamed:@"多边形1"];
        self.topView.height = 625 * SCREENH6;
        
        self.timeShowLabel.hidden = NO;
        self.dateLabel.hidden = YES;
        self.timeLabel.hidden = YES;
        self.workDayButton.hidden = YES;
        self.weekDayButton.hidden = YES;
        self.everyDayButton.hidden = YES;
        self.timeStartButton.hidden = YES;
        self.toLabel.hidden = YES;
        self.timeEndButton.hidden = YES;
        self.timeSureButton.hidden = YES;
        
        NSString * weekDay;
        if (self.workDayButton.selected) {
            
            weekDay = @"工作日";
        }else if (self.weekDayButton.selected){
            
            weekDay = @"周日";
        }else if (self.everyDayButton.selected){
            
            weekDay = @"每天";
        }
        NSString * time = [NSString stringWithFormat:@"%@-%@",self.timeStartButton.titleLabel.text,self.timeEndButton.titleLabel.text];
        self.timeShowLabel.textColor = ZRBlackColor;
        self.timeShowLabel.text = [NSString stringWithFormat:@"%@ %@",weekDay,time];
        
        [self reloadButtonState];
        
    }else{
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"请先选择营业时间"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
    
    
}


- (void)presentDateController{
    
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    PGDatePicker *datePicker = datePickManager.datePicker;
    datePicker.delegate = self;
    datePicker.datePickerType = PGDatePickerType1;
    datePicker.isHiddenMiddleText = false;
    datePicker.datePickerMode = PGDatePickerModeTime;
    //    datePicker.maximumDate = [NSDate date];
    datePicker.language = @"zh-Hans";
    [self presentViewController:datePickManager animated:false completion:nil];
}


#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    
    NSString * date = [NSString stringWithFormat:@"%li:%02li",(long)dateComponents.hour,(long)dateComponents.minute];
    
    
    if ([self.chooseTimeType isEqualToString:@"start"]) {
        
        self.timeStartButton.selected = YES;
        [self.timeStartButton setTitle:date forState:UIControlStateNormal];
    }else{
        
        self.timeEndButton.selected = YES;
        [self.timeEndButton setTitle:date forState:UIControlStateNormal];
    }
    
}


@end
